package thread.concurrents.aqs;

import java.util.concurrent.locks.Condition;
import java.util.concurrent.locks.ReentrantLock;
import java.util.concurrent.locks.ReentrantReadWriteLock;

public class ReadAndWriterLock {

  public static void main(String[] args) {


    ReadAndWriterLock readAndWriterLock = new ReadAndWriterLock();

    ReentrantReadWriteLock lock = new ReentrantReadWriteLock();

    //演示读写锁会排队吗？
  new Thread(new Runnable() {
      @Override
      public void run() {
        lock.readLock().lock();
        System.out.println("A");
      }
    }).start();

    new Thread(new Runnable() {
      @Override
      public void run() {
        lock.writeLock().lock();

      }
    }).start();

    new Thread(new Runnable() {
      @Override
      public void run() {
        try {
          Thread.sleep(3000L);
        } catch (InterruptedException e) {
          e.printStackTrace();
        }
        lock.readLock().lock();
        System.out.println("AA 读锁再次进入");
      }
    }).start();





  }





}
